<!DOCTYPE html>
<html>
<head>
<title>Charge Distribution Diagram</title>
</head>
<body>

<canvas id="physicsCanvas" width="500" height="450" style="border:1px solid #d3d3d3;"></canvas>

<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // Define coordinates based on a scale and origin
    const origin = { x: 100, y: 380 };
    const sideLengthPixels = 280;

    const B_coord = { x: origin.x, y: origin.y };
    const A_coord = { x: origin.x + sideLengthPixels, y: origin.y };
    const C_coord = { x: origin.x, y: origin.y - sideLengthPixels };
    const M_coord = { x: (A_coord.x + C_coord.x) / 2, y: (A_coord.y + C_coord.y) / 2 };

    // Define styles
    const chargeRadius = 15;
    const mRadius = 9;
    const lineWidth = 3;
    const lineColor = '#00529B'; // A strong blue for lines
    const circleColor = '#4169E1'; // Royal blue for circles
    const textColor = 'black';
    const valueFont = 'bold 22px Arial';
    const labelFont = 'bold 28px Arial';

    // Helper function to draw a filled circle
    function drawCircle(x, y, radius, color) {
        ctx.beginPath();
        ctx.arc(x, y, radius, 0, 2 * Math.PI);
        ctx.fillStyle = color;
        ctx.fill();
    }

    // Clear canvas
    ctx.clearRect(0, 0, canvas.width, canvas.height);

    // Draw triangle lines
    ctx.beginPath();
    ctx.moveTo(A_coord.x, A_coord.y);
    ctx.lineTo(B_coord.x, B_coord.y);
    ctx.lineTo(C_coord.x, C_coord.y);
    ctx.lineTo(A_coord.x, A_coord.y);
    ctx.strokeStyle = lineColor;
    ctx.lineWidth = lineWidth;
    ctx.stroke();

    // Draw charges and point M
    drawCircle(A_coord.x, A_coord.y, chargeRadius, circleColor);
    drawCircle(B_coord.x, B_coord.y, chargeRadius, circleColor);
    drawCircle(C_coord.x, C_coord.y, chargeRadius, circleColor);
    drawCircle(M_coord.x, M_coord.y, mRadius, circleColor);

    // Draw all text labels
    ctx.fillStyle = textColor;

    // --- Point Labels (A, B, C, M) ---
    ctx.font = labelFont;
    // Label C
    ctx.textAlign = 'center';
    ctx.textBaseline = 'bottom';
    ctx.fillText('C', C_coord.x, C_coord.y - chargeRadius - 5);
    // Label B
    ctx.fillText('B', B_coord.x, B_coord.y - chargeRadius - 5);
    // Label A
    ctx.textAlign = 'left';
    ctx.textBaseline = 'middle';
    ctx.fillText('A', A_coord.x + chargeRadius + 10, A_coord.y);
    // Label M
    ctx.fillText('M', M_coord.x + mRadius + 10, M_coord.y);

    // --- Value Labels (charges and lengths) ---
    ctx.font = valueFont;
    // Charge at C
    ctx.textAlign = 'right';
    ctx.textBaseline = 'middle';
    ctx.fillText('+10\u00B5C', C_coord.x - chargeRadius - 10, C_coord.y);
    // Charge at B
    ctx.fillText('+2\u00B5C', B_coord.x - chargeRadius - 10, B_coord.y);
    // Length of BC
    ctx.fillText('5 cm', C_coord.x - 35, (C_coord.y + B_coord.y) / 2);

    // Length of AB
    ctx.textAlign = 'center';
    ctx.textBaseline = 'top';
    ctx.fillText('5 cm', (A_coord.x + B_coord.x) / 2, B_coord.y + 15);
    // Charge at A
    ctx.fillText('+10\u00B5C', A_coord.x, A_coord.y + chargeRadius + 10);

</script>

</body>
</html>